package com.weayer.dto;

import com.weayer.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @description: 统一响应结果
 * @author: Weayer
 **/
@Data
@Accessors(chain = true)    // 链式调用
public class ResponseResult<T> {
    private int code;
    private String message;
    private T data;

    // 响应成功
    public static <T> ResponseResult success(){
        return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue());
    }

    public static <T> ResponseResult success(T data){
        return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue()).setData(data);
    }

    // 响应失败
    public static <T> ResponseResult fail(T data){
        return new ResponseResult().setData(data);
    }

    public static ResponseResult fail(int code, String message){
        return new ResponseResult().setCode(code).setMessage(message);
    }

    public static <T> ResponseResult fail(int code, String message, T data){
        return new ResponseResult().setCode(code).setMessage(message).setData(data);
    }
}
